package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * 将教语文的老师工资涨500
 * 测试事务的提交与回滚
 */
public class Test {
     public static void main(String[] args) {
          try(Connection conn = DBUtil.getConnection();) {
             conn.setAutoCommit(false);
             String sql = "UPDATE teacher " +
                          "SET salary = salary + 500 " +
                          "WHERE subject_id = (SELECT id FROM subject WHERE name = '语文' )";
             Statement st = conn.createStatement();
             int num = st.executeUpdate(sql);
             System.out.println(num>0? "更新成功":"更新失败");

             conn.commit();
         } catch (SQLException e) {
             e.printStackTrace();
         }
    }
}
